Skip to content

feat: offline-first PWA mobile companion for field incident capture#324

Open
utkarshqz wants to merge 5 commits intofireform-core:mainfrom
utkarshqz:feat/pwa-mobile-companion
Open

feat: offline-first PWA mobile companion for field incident capture#324
utkarshqz wants to merge 5 commits intofireform-core:mainfrom
utkarshqz:feat/pwa-mobile-companion

Conversation

@utkarshqz
Copy link

Description

Speak once at the scene. Pick up the PDF at the station.

FireForm fills forms. This PR takes it to where incidents actually happen.

First responders work in basements, forests, and remote areas — no WiFi, sometimes no cellular. The current interface requires a constant station connection, making it unusable in the field. Officers capture on paper, return to the station, and re-enter everything manually. That is exactly the redundant work FireForm was built to eliminate.

This PR adds a minimal Progressive Web App at /mobile — served by the existing FastAPI server, installable on any phone via "Add to Home Screen", and fully functional offline. No app store. No native code. No new infrastructure.

Closes #323


The Field Scenario

Officer arrives at scene — no WiFi, no cellular
  → Records 30s voice memo offline
  → GPS coordinates captured automatically
  → Types supplementary notes
  → Draft saved to phone's IndexedDB

Officer returns to station — WiFi restored
→ App detects connection automatically
→ Taps Send → selects agency templates
→ Audio transcribed by faster-whisper at station
→ Text + transcript combined → one LLM call
→ All agency PDFs filled simultaneously
→ Officer downloads forms before shift ends


What Was Built

Three new files:

mobile/index.html — Complete PWA with three tabs:

CAPTURE — Live clock with date, auto-generated incident ID (INC-2026-0321-4821 format), GPS capture via device satellite GPS (works fully offline), voice recording with timer, text notes textarea, media capture placeholder marked as proposed future feature.

DRAFTS — All saved reports with PENDING/SYNCED status. Shows text preview and audio indicator. Edit with additional audio recordings — multiple recordings per draft, all transcribed and combined. Play back recorded audio. Send to station with template selector. PDF download buttons appear only after generation. Delete. Clear offline/online status indicator.

SUBMIT — Template multi-select, text pre-loaded from draft, audio playback, single or batch fill, per-template download links.

mobile/manifest.json — Web App Manifest for installable PWA behavior.

mobile/sw.js — Service Worker with aggressive caching:

  • App shell → cache-first, always available offline
  • API calls → network-only, graceful offline response
  • Offline fallback → cached shell loads with zero connectivity

One modified file:

api/main.py — mounts mobile/ as StaticFiles at /mobile. Two lines added.


Audio + Text Combination

Draft has typed notes + recorded audio:
  → Station receives both on sync
  → Audio transcribed by faster-whisper
  → Transcript appended to existing text
  → Combined text sent to LLM for extraction
  → Richer extraction from both sources

Multiple recordings per draft:
→ All blobs transcribed sequentially
→ All transcripts joined with spaces
→ Combined with any existing typed notes


Offline Behaviour

Feature Offline Needs Station
App loads from cache
Type notes
Save draft to IndexedDB
GPS coordinates ✅ (satellite)
Live clock
Voice recording
Auto-sync on reconnect
Voice transcription
PDF filling

On HTTPS and ngrok

Microphone and Geolocation require HTTPS — a browser security standard, not a FireForm limitation. For production deployment, a self-signed SSL certificate on the station PC resolves this permanently. For demo and testing, ngrok provides an HTTPS tunnel to the local FastAPI server:

ngrok http 8000
# https://[url].ngrok-free.app → http://localhost:8000

ngrok is used only because it provides valid HTTPS for testing on physical devices. In real deployment, officers connect via station WiFi. All data stays on-premise — critical for CJIS compliance.


Proposed Future Extensions

The disabled media capture section shows the intended roadmap:

  • Photo and video capture stored in IndexedDB, sent to station Vision LLM for field extraction
  • Multi-officer report unification — group by incident ID, merge fields, flag conflicts
  • Push notifications when PDFs are ready
  • Native Android APK via Capacitor for true device storage

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • PWA installed on Android tablet via ngrok HTTPS URL
  • Voice recording stored and played back correctly
  • Draft saved offline (WiFi disabled) — persists after app close
  • GPS coordinates captured on tablet
  • Auto-sync on WiFi reconnection
  • Audio transcribed via faster-whisper at station
  • Text + audio combined before LLM extraction
  • Batch template filling from mobile
  • PDF download links appear only after generation
  • Edit modal with multiple audio recordings
  • Clear offline/online status indicator

Test Configuration:

  • Device: Android tablet (Chrome)
  • Server: Windows 11, Python 3.11, Ollama local, mistral
  • HTTPS: ngrok tunnel
  • Network: Local WiFi + offline simulation (WiFi toggle)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Documentation: docs/SETUP.md updated with complete PWA setup guide — ngrok setup, Android/iOS install instructions, and production self-signed certificate deployment. @marcvergees @vharkins1 — this takes FireForm from station-only to field-ready. The "Report Once, File Everywhere" promise now extends to where incidents actually happen. Would value your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Offline-first mobile companion app for field incident capture

1 participant